package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.ConsumerJTO;
import com.xingkeduo.business.transformation.json.ConsumerPrivateJTO;
import com.xingkeduo.business.transformation.json.ConsumerStatisticsJTO;
import com.xingkeduo.business.user.domain.ConsumerDomain;
import com.xingkeduo.pojo.query.ConsumerPrivateQO;
import com.xingkeduo.pojo.query.ConsumerQO;
import com.xingkeduo.pojo.query.ConsumerStatisticsQO;
import com.xingkeduo.pojo.table.ConsumerTO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.domain.PageJTO;
import com.xingkeduo.util.tool.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/2/18 19:00
 **/
//@CrossOrigin
@RestController
@RequestMapping("/consumer/list")
public class ConsumerListController extends BaseController {

    @Autowired
    private ConsumerDomain consumerDomain;

    /** 查询分页消费者列表   判断有公众号为微信粉丝
     * @return : com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.xingkeduo.pojo.query.ConsumerOrderQO>
     * @author : gaozifeng
     * @date : 2019/2/21 13:54
     */
    @GetMapping(value = "/{json:.+}")
    public String selectConsumerAllByPage(@PathVariable String json, int page, int limit) throws Throwable {
        returnUtil = new ReturnUtil();
        try {
            ConsumerQO consumerQO = ConsumerJTO.createQueryForList(json);
            ConsumerStatisticsQO consumerStatisticsQO= ConsumerStatisticsJTO.createQueryConditionByTotal(json);
            ConsumerPrivateQO privateQO = ConsumerPrivateJTO.createQueryCondition(json);
            Page<ConsumerTO> pageDO = new Page<ConsumerTO>(page, limit);
            return returnUtil.getSuccess(PageJTO.toJson(pageDO, ConsumerJTO.toJson(
                    consumerDomain.selectConsumerAllByPage(consumerQO,consumerStatisticsQO,privateQO, pageDO))));
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }
}
